import Vue from 'vue'
import VueI18n from 'vue-i18n'
import locale from 'element-ui/lib/locale'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN.js'
import enLocale from 'element-ui/lib/locale/lang/en.js'
import entxt from './en.js'
import zhtxt from './zh-CN.js'
import Cookies from 'js-cookie'

Vue.use(VueI18n)

let defaultLang = navigator.language

const messages = {
  'en': {
    ...entxt,
    ...enLocale
  },
  'zh-CN': {
    ...zhtxt,
    ...zhLocale
  }
}

const i18n = new VueI18n({
  locale: Cookies.get('language') || defaultLang, // set locale
  messages // set locale messages
})
locale.i18n((key, value) => i18n.t(key, value))

export default i18n
